﻿Namespace Data
    Public Class DateTimeToStringConverter
        Implements IValueConverter

        Public Function Convert(value As Object, targetType As Type, parameter As Object, language As String) As Object Implements IValueConverter.Convert
            Dim datetime = CDate(value)
            Dim yearNum = datetime.Year
            Dim year = yearNum.ToString
            Dim monthNum = datetime.Month
            Dim month = monthNum.ToString
            Dim dayNum = datetime.Day
            Dim day = dayNum.ToString
            Return year & " 年 " & month & " 月 " & day & " 日 "
        End Function

        Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, language As String) As Object Implements IValueConverter.ConvertBack
            Dim setValue = value.ToString
            Dim d As DateTime
            If DateTime.TryParse(setValue, d) Then
                Return d
            End If
            Return value
        End Function
    End Class
End Namespace